import pymysql

mysql_info = {
    'host': '127.0.0.1',
    'port': 3306,
    'user': 'root',
    'password': '123456',
    'database': 'test',
}

# 查询
# conn = pymysql.connect(**mysql_info)
# con = conn.cursor()
# con.execute('select * from articel')
# ret = con.fetchone()
# print(ret)

# 插入
# conn = pymysql.connect(**mysql_info)
# con = conn.cursor()
# # con.execute('insert into articel values ("book","123",null)')
# title = "book7"
# content = "1234567890"
# sql = 'insert into articel values (%s,%s,null)'
# con.execute(sql,(title,content))
# conn.commit()
# conn.close()


# 获取数据
# conn = pymysql.connect(**mysql_info)
# con = conn.cursor()
# sql = 'select * from articel where id>3'
# con.execute(sql)
# ret = con.fetchall()
# for i in ret:
#     print(i)


# 删除数据
# conn = pymysql.connect(**mysql_info)
# con = conn.cursor()
# sql = 'delete from articel where id=3'
# con.execute(sql)
# conn.commit()
# conn.close()


# 更新数据
conn = pymysql.connect(**mysql_info)
con = conn.cursor()
sql = 'update articel set title="钢铁是怎么炼成的" where id=1'
con.execute(sql)
conn.commit()
conn.close()




